package tec;

public abstract class  PassagerAbstrait extends Passager  
{  
   private Comportement  c;
   private String nom ;
   private final int DESTINATION ;
   private EtatPassager etat ;

    public PassagerAbstrait(String nom, int destination, Comportement c)
    {  if( destination<0)
	    throw new IllegalArgumentException("La destination doit etre positive");
       this.nom = nom ;
       DESTINATION = destination ;
       etat = EtatPassager.dehors;
       this.c = c;
   }

    protected final void accepterPlaceAssise()
    {
	etat = EtatPassager.assis;
    }
    
    protected final  void accepterPlaceDebout()
    {
	etat = EtatPassager.debout;
    }
    
     protected final void accepterSortie()
    {
	etat = EtatPassager.dehors;

    }
    
     protected final boolean estAssis()
    {
	return etat.estAssis() ;
    }
    
    protected final boolean estDebout()
    {
	return etat.estDebout() ;
    }
    
    protected final boolean estDehors()
    {
	return !estAssis() && !estDebout() ;
    }
    
    
    public final  String toString()
    {
	return (nom + " " + etat).toLowerCase();
    }	
    
    final int getDestination(){
	return DESTINATION;
    }
			   
    


    public final String nom()
    {
	return nom;
    }



    protected abstract void choixPlaceMontee(Bus b);
    
    public final void monterDans(Transport t) throws TecInvalidException, IllegalStateException{
	if(!(t instanceof Bus))
	    throw new TecInvalidException();
	Bus b= (Bus) t;
	if(this.etat != EtatPassager.dehors)
	    throw new IllegalStateException();
	Autobus temp = (Autobus) b;
	if(this.getDestination()-temp.numeroArret<=0)
		throw new IllegalStateException();

	choixPlaceMontee(b);
    }

    protected final void nouvelArret(Bus b, int numeroArret) throws TecInvalidException
    {

	if(getDestination() == numeroArret){
    		b.demanderSortie(this);
        }
	c.choixChangerPlace(b,this,numeroArret);
    }


 

}

